CAMEL-23479: Fix camel.main.virtualThreadsEnabled not working#23307
Conversation
Two bugs fixed: 1. Race condition: autoconfigure() set the system property after camelContext.build() could already have triggered ThreadType.current() and permanently cached PLATFORM via double-checked locking. 2. Programmatic case broken: main.configure().withVirtualThreadsEnabled(true) set mainConfigurationProperties but never set the system property, so ThreadType.current() always returned PLATFORM. Fix: add configureVirtualThreadsEarly() called before camelContext.build() that checks all config sources (programmatic, initialProperties, PropertiesComponent, ENV, JVM system props) and sets the system property early. Also adds ThreadType.enable() to directly set the cached value, overriding any value already cached before this point. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
| // configure custom main listeners | ||
| configureMainListener(camelContext); | ||
| // configure virtual threads early before build() to avoid ThreadType DCL race | ||
| configureVirtualThreadsEarly(camelContext); |
There was a problem hiding this comment.
is https://github.com/davsclaus/camel/blob/e93773b5b3e3cbd992c5170b905614b738160a96/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java#L593 still needed? or can be removed in favour of configureVirtualThreadsEarly ?
There was a problem hiding this comment.
Good catch! Yes, the autoConfigurationSingleOption call for virtualThreadsEnabled is now redundant — configureVirtualThreadsEarly() covers all the same configuration sources and runs at the right moment (before camelContext.build()). Removed it in the follow-up commit.
Claude Code on behalf of Claus Ibsen
|
🌟 Thank you for your contribution to the Apache Camel project! 🌟 🐫 Apache Camel Committers, please review the following items:
|
…SingleOption configureVirtualThreadsEarly() now covers all configuration sources and runs before camelContext.build(), making the later autoConfigurationSingleOption call for virtualThreadsEnabled redundant. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
🧪 CI tested the following changed modules:
Build reactor — dependencies compiled but only changed modules were tested (2 modules)
|
Summary
Fixes two distinct bugs where
camel.main.virtualThreadsEnabled=truefailed to enable virtual threads:autoconfigure()set the system propertycamel.threads.virtual.enabledaftercamelContext.build()had already triggeredThreadType.current(), which uses a permanent double-checked-locking cache. Once cached asPLATFORM, the value was never re-evaluated.main.configure().withVirtualThreadsEnabled(true)setmainConfigurationProperties.virtualThreadsEnabled=truebutautoConfigurationSingleOptiononly reads external sources — the system property was never set, soThreadType.current()always returnedPLATFORM.Fix:
configureVirtualThreadsEarly()toBaseMainSupport, called beforecamelContext.build(). It checks all config sources in priority order: programmatic →initialProperties→PropertiesComponent(application.properties) → ENV vars → JVM system props.ThreadType.enable()incamel-utilto directly set the cached value toVIRTUAL, overriding any value that may have been cached earlier in the bootstrap sequence.MainVirtualThreadsTestcovering both previously-broken paths.Test plan
MainVirtualThreadsTest.testProgrammaticVirtualThreadsEnabled— verifiesmain.configure().withVirtualThreadsEnabled(true)correctly setsThreadType.VIRTUALMainVirtualThreadsTest.testInitialPropertyVirtualThreadsEnabled— verifiesmain.addInitialProperty("camel.main.virtualThreadsEnabled", "true")correctly setsThreadType.VIRTUALcamel-maintest suiteRelates to: https://issues.apache.org/jira/browse/CAMEL-23479
Claude Code on behalf of Claus Ibsen
🤖 Generated with Claude Code